﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Attributes;
using UtilZ.Dotnet.Ex.Model;

namespace ConAppCore
{
    internal class TestObjectBuilder
    {
        public static void Test()
        {
            //Test1();
            //Test5();

            TestBuilderConstructor();
        }

        private static void TestBuilderConstructor()
        {
            try
            {
                var objBuilder0 = new ObjectBuilder<int, IObjectBuildInterface1>(null, new Type[] { typeof(string) });
                objBuilder0.RegisteType<ObjectBuildA>();
                objBuilder0.RegisteType<ObjectBuildB>();
                //objBuilder0.RegisteType<ObjectBuildC>();

                var obj10 = objBuilder0.Create(ObjectBuildConstant.AAA);
                //var obj11 = objBuilder0.Create(ObjectBuildConstant.AAA, new object[] { 1 });
                //var obj12 = objBuilder0.Create(ObjectBuildConstant.AAA, new object[] { "aa" });

                var obj20 = objBuilder0.Create(ObjectBuildConstant.BBB);
                var obj21 = objBuilder0.Create(ObjectBuildConstant.BBB, new object[] { "aa" });
                var obj22 = objBuilder0.Create(ObjectBuildConstant.BBB, new object[] { 23 });

                //var obj30 = objBuilder0.Create(ObjectBuildConstant.CCC);
                //var obj31 = objBuilder0.Create(ObjectBuildConstant.CCC);
            }
            catch (Exception ex)
            {

            }
        }
        private static void Test5()
        {
            try
            {
                //var objBuilder0 = new ObjectBuilder<int, IObjectBuildInterface2>();
                //objBuilder0.RegisteType<ObjectBuildA>();
                //objBuilder0.RegisteType<ObjectBuildB>();
                //objBuilder0.RegisteType<ObjectBuildC>();
                //var obj0 = objBuilder0.Create(ObjectBuildConstant.AAA);

                var objBuilder0 = new ObjectBuilder<int, ObjectBuildAbs>();
                objBuilder0.RegisteType<ObjectBuildA>();
                objBuilder0.RegisteType<ObjectBuildB>();
                objBuilder0.RegisteType<ObjectBuildC>();
                var obj0 = objBuilder0.Create(ObjectBuildConstant.AAA);

                var objBuilder1 = new ObjectBuilder<int, IObjectBuildInterface1>(typeof(ObjectBuildAbs), null);
                objBuilder1.RegisteType<ObjectBuildA>();
                objBuilder1.RegisteType<ObjectBuildB>();
                objBuilder1.RegisteType<ObjectBuildC>();
                IObjectBuildInterface1 obj1 = objBuilder1.Create(ObjectBuildConstant.AAA);


                var objBuilder2 = new ObjectBuilder<int, ObjectBuildAbs>(typeof(ObjectBuildAbs), null);
                objBuilder2.RegisteType<ObjectBuildA>();
                objBuilder2.RegisteType<ObjectBuildB>();
                objBuilder2.RegisteType<ObjectBuildC>();
                ObjectBuildAbs obj2 = objBuilder2.Create(ObjectBuildConstant.AAA);

                var objBuilder3 = new ObjectBuilder<int, IObjectBuildInterface1>(typeof(ObjectBuildAbs), new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                objBuilder3.RegisteType<ObjectBuildA>();
                objBuilder3.RegisteType<ObjectBuildB>();
                objBuilder3.RegisteType<ObjectBuildC>();
                IObjectBuildInterface1 obj3 = objBuilder3.Create(ObjectBuildConstant.AAA);

                var objBuilder4 = new ObjectBuilder<int, ObjectBuildAbs>(typeof(ObjectBuildAbs), new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                objBuilder4.RegisteType<ObjectBuildA>();
                objBuilder4.RegisteType<ObjectBuildB>();
                objBuilder4.RegisteType<ObjectBuildC>();
                ObjectBuildAbs obj4 = objBuilder4.Create(ObjectBuildConstant.AAA);

                var objBuilder5 = new ObjectBuilder<int, IObjectBuildInterface1>(null, new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                objBuilder5.RegisteType<ObjectBuildA>();
                objBuilder5.RegisteType<ObjectBuildB>();
                objBuilder5.RegisteType<ObjectBuildC>();
                IObjectBuildInterface1 obj5 = objBuilder5.Create(ObjectBuildConstant.AAA);

                var objBuilder6 = new ObjectBuilder<int, ObjectBuildAbs>(null, new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                objBuilder6.RegisteType<ObjectBuildA>();
                objBuilder6.RegisteType<ObjectBuildB>();
                objBuilder6.RegisteType<ObjectBuildC>();
                ObjectBuildAbs obj6 = objBuilder6.Create(ObjectBuildConstant.AAA);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

        private static void Test1()
        {
            try
            {
                var objBuilder1 = new ObjectBuilder<int, IObjectBuildInterface1>(null, null);
                var objBuilder2 = new ObjectBuilder<int, IObjectBuildInterface1>(typeof(ObjectBuildAbs), null);
                var objBuilder3 = new ObjectBuilder<int, IObjectBuildInterface1>(null, new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                var objBuilder4 = new ObjectBuilder<int, IObjectBuildInterface1>(null, new Type[] { typeof(IObjectBuildInterface2) });
                var objBuilder5 = new ObjectBuilder<int, IObjectBuildInterface1>(typeof(ObjectBuildAbs), new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                var objBuilder6 = new ObjectBuilder<int, IObjectBuildInterface1>(typeof(ObjectBuildAbs), new Type[] { typeof(IObjectBuildInterface2) });


                var objBuilder21 = new ObjectBuilder<int, ObjectBuildAbs>(typeof(ObjectBuildAbs), null);
                var objBuilder22 = new ObjectBuilder<int, ObjectBuildAbs>(typeof(ObjectBuildA), null);
                var objBuilder23 = new ObjectBuilder<int, ObjectBuildAbs>(null, null);

                var objBuilder24 = new ObjectBuilder<int, ObjectBuildAbs>(typeof(ObjectBuildAbs), new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                var objBuilder25 = new ObjectBuilder<int, ObjectBuildAbs>(typeof(ObjectBuildA), new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });
                var objBuilder26 = new ObjectBuilder<int, ObjectBuildAbs>(null, new Type[] { typeof(IObjectBuildInterface1), typeof(IObjectBuildInterface2) });

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }

    public interface IObjectBuildInterface1
    {

    }

    public interface IObjectBuildInterface2
    {

    }

    public struct ABCStr : IObjectBuildInterface2
    {

    }

    public abstract class ObjectBuildAbs : IObjectBuildInterface1
    {

    }


    [TestExtendIdAttribute(ObjectBuildConstant.AAA)]
    public class ObjectBuildA : ObjectBuildAbs, IObjectBuildInterface2
    {
        public ObjectBuildA(int a)
        {

        }

        public ObjectBuildA()
        {

        }
    }

    [TestExtendIdAttribute(ObjectBuildConstant.BBB)]
    public class ObjectBuildB : ObjectBuildAbs
    {
        public ObjectBuildB(string str)
        {

        }

        public ObjectBuildB()
        {

        }
    }

    [ObjectBuildIdAttribute(ObjectBuildConstant.CCC)]
    public class ObjectBuildC
    {

    }

    public class ObjectBuildConstant
    {
        public const int AAA = 1;
        public const int BBB = 2;
        public const int CCC = 3;
    }

    public class TestExtendIdAttribute : ObjectBuildIdAttribute
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id">类型标识</param>
        public TestExtendIdAttribute(int id)
            : base(id)
        {

        }
    }
}
